<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>可移动弹框</title>
  <style>
    .container {
      user-select: none;
      position: absolute;
      line-height: 200px;
      border-radius: 5px;
      box-shadow: 5px 5px #80808054;
      border: 2px solid gray;
      width: 20%;
      height: 200px;
      text-align: center;
      color: red;
      font-size: 20px;
      cursor: pointer;
      top: 168px;
      left: 38%;
    }

    body {
      height: 950px;
    }
  </style>
</head>

<body>
  <div class="container" id="box">移动弹框</div>
  <script>
    let box = document.getElementById("box");
    let body = document.getElementsByTagName("body")[0];

    body.style.height = window.innerHeight + 'px'

    let offLeft = 0;
    let offTop = 0;
    let mouseLeft = 0
    let mouseTop = 0
    box.addEventListener("mousedown", function (event) {
      offLeft = box.offsetLeft;
      offTop = box.offsetTop;

      mouseLeft = event.clientX
      mouseTop = event.clientY
      body.addEventListener("mousemove", move);
    });
    box.addEventListener("mouseup", function () {
      body.removeEventListener("mousemove", move);
    });
    function move(event) {
      box.style.left = offLeft + event.clientX - mouseLeft + 'px'
      box.style.top = offTop + event.clientY - mouseTop + 'px'
    }
  </script>
</body>

</html>